from exts import db
# from apps.basic.models import Address
from flask_login import UserMixin
from apps import login_manager
from apps.common.base_model import BaseModel


# 用户认证的回调函数
@login_manager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))


class User(UserMixin, BaseModel):
    __tablename__ = "t_user"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50), comment='用户名', nullable=False)
    password = db.Column(db.String(50), comment='密码', nullable=False)
    mobile = db.Column(db.String(50), comment='手机号码')
    sex = db.Column(db.Integer)
    birthday = db.Column(db.Date)
    # nickname=models.CharField('昵称',blank=True,max_length=50)
    email = db.Column(db.String(50), comment="邮箱")
    user_img = db.Column(db.String(50), comment="用户头像")
    level = db.Column(db.Integer, default=0)
    status = db.Column(db.Integer, default=0)

    # create_time=models.DateTimeField(default=datetime.now,verbose_name='创建时间')
    # update_time=models.DateTimeField(default=datetime.now,verbose_name="更新时间")

    def __repr__(self):
        return self.username
